# coding:utf-8
__author__ = 'Ybj'
'''
description:微课作业页
'''
from src.common import Base_page
from appium.webdriver.common import mobileby
from airtest.core.api import *
from appium.webdriver.webelement import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
from poco.proxy import *
import time,datetime,locale
from src.common.datetime import *
from testdata.workdata import *
from src.common.baseUrl import *
from src.pages.work.teaAttach_page import *
from src.pages.work.teaAttach_page import *
auto_setup(__file__)

poco= AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
#获取档期日期
dd=get_current_date(is_chinese=True)

url= baspath()
teaV_W_url=baspath()+"\\pages\\image\\work\\"
class teaHome_page(Base_page.Base_page):

    # ******************************页面元素   开始*************************
    #页面标题
    tHtitle = poco("课后练习")
    #练习名称

    #未选择
    tNosel = poco("未选择")
    #科目
    tsubject=poco(subject)
    #英语科目
    tsubjectE = poco(subjectE)

    tHconfirm=poco("确认")

    tHallSle=poco("全选")

    tsendkey=poco("发布")

    read=poco("课本跟读")
    kuau=poco("自由组卷")
    error= poco("错题练习")
    tQuict = poco("快速布置")

    viocesC=poco("android:id/alertTitle")
    viocesO=poco("com.android.packageinstaller:id/permission_allow_button")
    #去预览
    preView=poco("去预览")
    #学习内容未填

    noitmes=poco("共0题，大约需要0分钟完成")
    #普通课程班级
    tclaNo=poco(claNo)
    tver =poco(ver)

    #英语跟读班级
    tverE=poco(verE)
    tclaNoE =poco(claNoE)
    #跟读页全选
    allSleE=poco("去发布").parent().children()[1]
    #发布作业时，确认发布框
    review = poco("预览")
    tGsend=poco("去发布")
    tsendSuss=poco("发布成功")
    # ******************************页面元素   结束*************************

    # ******************************页面操作   开始*************************
    #设置普通作业年级章节
    def setChapter(self):
        teaHome_page.click_element(teaHome_page.tsubject)
        i= poco.get_screen_size()
        if len(teaHome_page.tNosel) ==0:
            print("章节已设定")
        elif len(teaHome_page.tNosel) == 1:
            teaHome_page.click_element(teaHome_page.tNosel)
            teaHome_page.click_element(teaHome_page.tHallSle)
            teaHome_page.click_element(teaHome_page.tHconfirm)
        elif len(teaHome_page.tNosel) == 2:
            teaHome_page.click_element(teaHome_page.tNosel[0])
            if not teaHome_page.tver.exists():
                for i in range(1,10):
                    swipe((int(i[0]/10), int(i[1]/3*2)), int(i[0]/10), int(i[1]/3))
                    if teaHome_page.tver.exists():
                        break


            teaHome_page.click_element(teaHome_page.tver)
            teaHome_page.click_element(teaHome_page.tclaNo)
            teaHome_page.click_element(teaHome_page.tHconfirm)
            teaHome_page.click_element(teaHome_page.tNosel[1])
            teaHome_page.click_element(teaHome_page.tHallSle)
            teaHome_page.click_element(teaHome_page.tHconfirm)
    #设置英语班级，可测试跟读作业
    def setChapterE(self,):
        teaHome_page.click_element(teaHome_page.tsubjectE)
        i= poco.get_screen_size()
        if len(teaHome_page.tNosel) ==0:
            print("章节已设定")
        elif len(teaHome_page.tNosel) == 1:
            teaHome_page.click_element(teaHome_page.tNosel)
            teaHome_page.click_element(teaHome_page.tHallSle)
            teaHome_page.click_element(teaHome_page.tHconfirm)
        elif len(teaHome_page.tNosel) == 2:
            teaHome_page.click_element(teaHome_page.tNosel[0])
            if not teaHome_page.tverE.exists():
                for i in range(1,10):
                    swipe((int(i[0]/10), int(i[1]/3*2)), int(i[0]/10), int(i[1]/3))
                    if teaHome_page.tverE.exists():
                        break


            teaHome_page.click_element(teaHome_page.tverE)
            teaHome_page.click_element(teaHome_page.tclaNoE)
            teaHome_page.click_element(teaHome_page.tHconfirm)
            teaHome_page.click_element(teaHome_page.tNosel[1])
            teaHome_page.click_element(teaHome_page.tHallSle)
            teaHome_page.click_element(teaHome_page.tHconfirm)

    def send(self):
        for i in range(1, 30):
            if teaHome_page.noitmes.exists():
                sleep(2)
            else:
                break
        teaHome_page.click_element(teaHome_page.tHallSle)
        teaHome_page.click_element(teaHome_page.preView)
        teaHome_page.click_element(teaHome_page.tGsend)
        teaAttach_page.setClass(self)
        teaHome_page.click_element(teaHome_page.tsendkey)
    def sendE(self):
        teaHome_page.click_element(teaHome_page.tGsend)
        teaAttach_page.setClass(self)
        teaHome_page.click_element(teaHome_page.tsendkey)
    # ******************************页面操作   结束*************************